package com.ruoyi.asset.controller;

import java.util.List;

import com.ruoyi.common.core.domain.Ztree;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstFactory;
import com.ruoyi.asset.service.IAstFactoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 厂家信息Controller
 * 
 * @author xunzhe
 * @date 2024-06-25
 */
@Controller
@RequestMapping("/asset/astFactory")
public class AstFactoryController extends BaseController
{
    private String prefix = "asset/astFactory";

    @Autowired
    private IAstFactoryService astFactoryService;

    @RequiresPermissions("asset:astFactory:view")
    @GetMapping()
    public String astFactory()
    {
        return prefix + "/astFactory";
    }

    /**
     * 查询厂家信息列表
     */
    @RequiresPermissions("asset:astFactory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AstFactory astFactory)
    {
        startPage();
        List<AstFactory> list = astFactoryService.selectAstFactoryList(astFactory);
        return getDataTable(list);
    }

    /**
     * 导出厂家信息列表
     */
    @RequiresPermissions("asset:astFactory:export")
    @Log(title = "厂家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstFactory astFactory)
    {
        List<AstFactory> list = astFactoryService.selectAstFactoryList(astFactory);
        ExcelUtil<AstFactory> util = new ExcelUtil<AstFactory>(AstFactory.class);
        return util.exportExcel(list, "厂家信息数据");
    }

    /**
     * 新增厂家信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存厂家信息
     */
    @RequiresPermissions("asset:astFactory:add")
    @Log(title = "厂家信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstFactory astFactory)
    {
        return toAjax(astFactoryService.insertAstFactory(astFactory));
    }

    /**
     * 修改厂家信息
     */
    @RequiresPermissions("asset:astFactory:edit")
    @GetMapping("/edit/{factoryId}")
    public String edit(@PathVariable("factoryId") Long factoryId, ModelMap mmap)
    {
        AstFactory astFactory = astFactoryService.selectAstFactoryByFactoryId(factoryId);
        mmap.put("astFactory", astFactory);
        return prefix + "/edit";
    }

    /**
     * 修改保存厂家信息
     */
    @RequiresPermissions("asset:astFactory:edit")
    @Log(title = "厂家信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstFactory astFactory)
    {
        return toAjax(astFactoryService.updateAstFactory(astFactory));
    }

    /**
     * 删除厂家信息
     */
    @RequiresPermissions("asset:astFactory:remove")
    @Log(title = "厂家信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(astFactoryService.deleteAstFactoryByFactoryIds(ids));
    }

    @GetMapping("/selectFactoryTree")
    public String selectAstStoreroomTree()
    {
        return prefix + "/tree";
    }

    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = astFactoryService.selectFactoryTree();
        return ztrees;
    }

}
